<template>
	<view>
		<pdf-view v-if="type==='pdf'" :url="url"></pdf-view>
		<web-view v-else :webview-styles="webviewStyles" :src="url"></web-view>
	</view>
</template>

<script>
	import pdfView from '@/components/pdf-view/pdf-view.vue'
	export default {
		data() {
			return {
				webviewStyles: {
					progress: {
						color: '#FF3333'
					}
				},
				type: "",
				url: '',
				urlParse: 'https://view.officeapps.live.com/op/view.aspx?src='
			};
		},
		onNavigationBarButtonTap(e) {
			if (e.text === "Back") {
				uni.navigateBack({
					delta: 1
				});
			}
		},
		onLoad(params) {
			let params_url = params.url;
			this.type = params.type;
			switch (params.type) {
				case 'url':
					this.url = decodeURIComponent(params.url)
					break;
				case 'pdf':
					uni.setNavigationBarTitle({
						title: 'PDF预览'
					});
					this.url = decodeURIComponent(params.url)
					break;
				case 'xls':
					this.url = this.urlParse + decodeURIComponent(params_url);
					location.href = this.url;
					break;
				case 'ppt':
					this.url = this.urlParse + decodeURIComponent(params_url);
					location.href = this.url;
					break;
				case 'doc':
					this.url = this.urlParse + decodeURIComponent(params_url);
					location.href = this.url;
					break;
			}
		}
	}
</script>

<style lang="less">

</style>
